<template>
  <div class="app-container">

    <el-table
      element-loading-text="Loading"
      :data="inventList"
      border
      fit
      style="width: 100%"
      highlight-current-row
    >
      <el-table-column label="开始时间" align="center" >
        <template slot-scope="scope">{{ scope.row.startTime }}</template>
      </el-table-column>
      <el-table-column label="结束时间" align="center">
        <template slot-scope="scope">{{ scope.row.endTime }}</template>
      </el-table-column>
      <el-table-column label="在库件数" align="center">
        <template slot-scope="scope">{{ scope.row.inStock }}</template>
      </el-table-column>
      <el-table-column label="借出件数" align="center">
        <template slot-scope="scope">{{ scope.row.outStock }}</template>
      </el-table-column>
      <el-table-column label="异常件数" align="center">
        <template slot-scope="scope">{{ scope.row.warnStock }}</template>
      </el-table-column>
      <el-table-column label="盘点结论" align="center">
        <template slot-scope="scope">{{ scope.row.taskSpec }}</template>
      </el-table-column>
      <el-table-column label="任务状态" align="center">
        <template slot-scope="scope">{{ scope.row.taskStatus }}</template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180rem">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="findInvent(scope.row.taskId)">查看</el-button>
          <el-button type="danger" size="small" @click="delDeviceType(scope.row.taskId)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
    ></el-pagination>
  </div>
</template>

<script>
  import $ from "@/api/equipInvent"

  export default {
    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        inventList: [],
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        this.currentPage = 1
        $.tbsTaskList({
          pageIndex: this.currentPage,
          pageSize: this.pageSize
        }).then(res => {
          this.inventList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          console.log(this.inventList)
        })
      },

      findInvent(id) {
        this.$router.push({
          path: "find",
          query: {id: id}
        });
      },
      //删除设备
      delDeviceType(id) {
        this.$confirm("此操作将删除该盘点任务, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            $.tbTaskDelete({taskId: id}).then(response => {
              if (response.success) {
                this.$message({
                  type: "success",
                  message: "删除成功"
                });
                this.fetchData();
              }
            });
            //console.log(id)
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      },

      find(pageIndex){
        $.tbsTaskList({
          pageIndex: pageIndex,
          pageSize: this.pageSize,
        }).then(res => {
          this.inventList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // console.log(res.data)
        })
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },

      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },
    }
  }
</script>
<style>
  .el-tooltip__popper {
    max-width: 700px
  }
</style>

